package com.lansi.fb.person.service;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.lansi.fb.person.bean.Person;
import com.lansi.fb.person.mapper.PersonMapper;


@Service
public class PersonService implements IPersonService{
	@Resource
	private PersonMapper personMapper;
	public void register(Person person) {
		
		personMapper.insertPerson(person);
		
	}
	//根据id删除用户信息-可以批量删除
	public void delPerson(Integer[] ids) {
		personMapper.deletePerson(ids);
		
	}
	//单个删除用户，根据id
	public void delById(Integer id) {
		personMapper.deleteById(id);
		
	}
	//2.用户信息的修改
	public void updatePerson(Integer id, String username, String sex, Integer age, String worktype, String sn,
			String level, String cardid, String userid, String picture, String memo, Date ctime) {
		Person person = new Person();
		person.setId(id);
		person.setUsername(username);
		person.setSex(sex);
		person.setAge(age);
		person.setWorktype(worktype);
		person.setSn(sn);
		person.setLevel(level);
		person.setCardid(cardid);
		person.setUserid(userid);
		person.setPicture(picture);
		person.setMemo(memo);
		person.setCtime(ctime);
		personMapper.updatePerson(person);
		
	}
	//根据id查询用户信息
	public Person getPersonById(Integer id) {
		
		return personMapper.selectPersonById(id);
	}
	// 根据用户姓名查询用户信息
	public Person getPersonByUsername(String username) {
		
		return personMapper.selectPersonByUsername(username);
	}
	//根据性别查询用户信息
	public List<Person> getPersonBySex(String sex) {
		
		return personMapper.selectPersonBySex(sex);
	}
	// 根据职务查询用户信息
	public List<Person> getPersonByLevel(String level) {
		
		return personMapper.selectPersonByLevel(level);
	}
	//根据工卡ID查询用户信息
	public Person getPersonByCardid(String cardid) {
		
		return personMapper.selectPersonByCardid(cardid);
	}
	//根据年龄查询用户信息
	public List<Person> getPersonByAge(String age) {
		
		return personMapper.selectPersonByAge(age);
	}
	//根据工作种类查询用户信息
	public List<Person> getPersonByWorktype(String worktype) {
		
		return personMapper.selectPersonByWorktype(worktype);
	}
	//根据工号查询用户信息
	public List<Person> getPersonBySn(String sn) {
		
		return personMapper.selectPersonBySn(sn);
	}
	//根据身份证查询用户信息
	public List<Person> getPersonByUserid(String userid) {
		
		return personMapper.selectPersonByUserid(userid);
	}
	//查询数据库总计数据数量
	public Integer getPersoncount(	
			String username,
			Integer sex,
			Integer level,
			String cardid,
			Integer age,
			Integer worktype,
			String sn,
			String userid) {
		
		return personMapper.selectPersoncount(username, sex, level, cardid, age, worktype, sn, userid);
	}
	//根据用户选择的信息--查询出所有用户的信息
	public List<Person> getPerson(
			String username, 
			Integer sex,
			Integer level,
			String cardid,
			Integer age,
			Integer worktype,
			String sn,
			String userid,	
			Integer offset,
			Integer count) {
		
		return personMapper.selectPerson(username, sex, level, cardid, age, worktype, sn, userid, offset, count);
	}
	//上传图片
	public void updateImage(String picture, String userid) {
		personMapper.updateImage(picture, userid);
		
	}

}
